package com.example.leetdemo.finash;

public class Solution2038 {

    public boolean winnerOfGame(String colors) {
        String temp = colors;
        int countA = 0, countB = 0, sumA = 0, sumB = 0;
        for (int i = 0; i < colors.length(); i++) {
            if (colors.charAt(i) == 'A') {
                countA++;
                if (countB - 3 >= 0) {
                    sumB += countB - 2;
                }
                countB = 0;
            } else {
                countB++;
                if (countA - 3 >= 0) {
                    sumA += countA - 2;
                }
                countA = 0;
            }
        }
        if (countA > 2) {
            sumA += countA - 2;
        }
        if (countB > 2) {
            sumB += countB - 2;
        }
        return sumA > sumB;
    }

    public static void main(String[] args) {
        Solution2038 solution2038 = new Solution2038();
        System.err.println(solution2038.winnerOfGame("AAABABB"));
    }
}
